www.gusucode.com > VC++ 局部放大图像-源码程序 > VC++ 局部放大图像-源码程序/code/Eileen/EileenView.cpp

    //Download by http://www.NewXing.com
// EileenView.cpp : implementation of the CEileenView class
//

#include "stdafx.h"
#include "Eileen.h"

#include "EileenDoc.h"
#include "EileenView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEileenView

IMPLEMENT_DYNCREATE(CEileenView, CView)

BEGIN_MESSAGE_MAP(CEileenView, CView)
	//{{AFX_MSG_MAP(CEileenView)
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEileenView construction/destruction


CEileenView::CEileenView()
{
	// TODO: add construction code here
	recover = false;
	s = 30; d = 45;
	oldx=0;
	oldy=0;
}


CEileenView::~CEileenView()
{
}

BOOL CEileenView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEileenView drawing





void CEileenView::OnDraw(CDC* pDC)
{
	CEileenDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CBitmap bitmap;
	bitmap.LoadBitmap(IDB_HE);
	BITMAP bit;
	bitmap.GetBitmap(&bit);
	cdem.CreateCompatibleDC(pDC);
	cdem.SelectObject(&bitmap);
	pDC->StretchBlt(0,0,bit.bmWidth,bit.bmHeight,&cdem,0,0,bit.bmWidth,bit.bmHeight,SRCCOPY);
}



















/////////////////////////////////////////////////////////////////////////////
// CEileenView printing

BOOL CEileenView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEileenView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEileenView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEileenView diagnostics

#ifdef _DEBUG
void CEileenView::AssertValid() const
{
	CView::AssertValid();
}

void CEileenView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEileenDoc* CEileenView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEileenDoc)));
	return (CEileenDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEileenView message handlers





void CEileenView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	int dd;
	CRect srect,drect,mrect;//源

	srect.left = point.x - s;
	srect.top = point.y - s;
	srect.right = point.x + s;
	srect.bottom = point.y + s;
	
	drect.left = point.x - d;//目标
	drect.top = point.y - d;
	drect.right = point.x + d;
	drect.bottom = point.y + d;
	
	mrect.left = oldx - d;
	mrect.top = oldy - d;
	mrect.right = oldx + d;
	mrect.bottom = oldy + d;
	dd = 2*d;
	CDC * pDC = GetDC();
	OnPrepareDC(pDC);
	//放大图像
	if (recover)
	{
		pDC->BitBlt(mrect.left,mrect.top,dd,dd,
			&cdem,mrect.left,mrect.top,SRCCOPY);//复原操作 
	}
	pDC->StretchBlt(drect.left,drect.top,
		drect.Width(),drect.Height(),&cdem,srect.left,
		srect.top,srect.Width(),srect.Height(),SRCCOPY);	
	ReleaseDC(pDC);
	oldx = point.x; oldy = point.y;
	recover = true;

	CView::OnMouseMove(nFlags, point);
}